package com.ruoyi.ws.facade;


import java.util.List;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.AdminBook;
import com.ruoyi.system.domain.AdminSong;
import com.ruoyi.system.service.IAdminBookService;
import com.ruoyi.system.service.IAdminSongService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import static com.ruoyi.common.core.domain.AjaxResult.error;
import static com.ruoyi.common.core.domain.AjaxResult.success;

/**
 * 教材相关接口
 *
 * @author roytrack
 * @date 2020-05-25 17:37:24
 */
@RestController
@RequestMapping(path = "services/book")
public class BookResource {

  /**
   * LOGGER
   */
  private static final Logger LOGGER = LoggerFactory.getLogger(BookResource.class);
  @Autowired
  private IAdminBookService adminBookService;
  @Autowired
  private IAdminSongService adminSongService;

  /**
   * 获取所有教材
   * @return
   */
  @PostMapping("/getBookList")
  @ResponseBody
  public AjaxResult getBookList () {
    try {
      //获取所有教材
      AdminBook adminBook  = new AdminBook();
      List<AdminBook> adminSubjectList = adminBookService.selectAdminBookList(adminBook);
      return success(adminSubjectList);
    } catch (Exception e) {
      LOGGER.info("获取所有教材失败",e);
      return error("获取所有教材失败");
    }
  }

  /**
   * 获取教材下的曲目
   * @return
   */
  @PostMapping("/getSongListByBookId")
  @ResponseBody
  public AjaxResult getSongListByBookId (Long bookId) {
    try {
      //获取曲目
      AdminSong adminSong  = new AdminSong();
      adminSong.setBookId(bookId);
      List<AdminSong> adminSubjectList = adminSongService.selectAdminSongList(adminSong);
      return success(adminSubjectList);
    } catch (Exception e) {
      LOGGER.info("获取教材下的曲目失败",e);
      return error("获取教材下的曲目失败");
    }
  }
}
